package com.ego.member.controller;

import java.util.List;
import java.util.Map;

import com.ego.common.vo.PageVo;
import com.ego.member.vo.MemberSearchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ego.member.po.Member;
import com.ego.member.service.MemberService;
import com.ego.common.util.Result;

import javax.validation.Valid;

/**
 * @author KamTang
 * @program: ego
 * @description 会员控制器
 * @date 2022-11-13 13:28:12
 */
@RestController
@RequestMapping("member")
public class MemberController {

    @Autowired
    private MemberService memberService;

    /**
     * 获取近一周
     */
    @GetMapping("/getWeeklyRegisterData")
    public Result getWeeklyRegisterData() {
        Map<String, List<?>> res;
        try {
            res = memberService.getWeeklyRegisterData();
        } catch (Exception e) {
            return Result.error("服务器异常");
        }
        return Result.ok().put("data", res);
    }

    /**
     * 搜索
     */
    @PostMapping("/search")
    public Result search(@Valid @RequestBody MemberSearchVo search) {
        PageVo<Member> page = memberService.search(search);
        return Result.ok().put("page", page);
    }

    /**
     * 信息
     */
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") Long id) {
        Member member = memberService.getById(id);
        return Result.ok().put("member", member);
    }

}
